package cn.magictodo.weblog.admin.event.subscriber.redis;

import cn.magictodo.weblog.admin.event.DeleteArticleEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import static cn.magictodo.weblog.common.enums.RedisPrefixEnum.REDIS_IS_PUBLISH;

/**
 * 取消推送监听者
 *
 * @author liu
 * @since 2023-12-22 13:54
 */
@Component
@Slf4j
public class CancelIsPulishArtcleSubscriber implements ApplicationListener<DeleteArticleEvent> {
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public void onApplicationEvent(DeleteArticleEvent event) {
        Long articleId = event.getArticleId();
        redisTemplate.delete(REDIS_IS_PUBLISH.getPrefix() + articleId);
        log.info("取消推送文章事件消费成功，文章id：{}", articleId);
    }
}
